package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import com.lzx.iteam.EventDetailContentActivity;
import com.lzx.iteam.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static android.R.id.list;

/**
 * Created by zhangshuai on 15/10/12.
 */
public class VoteTopAdapter extends BaseAdapter {


    private Context mContext;
    private ArrayList<String> mData;
    private boolean isShowCheck;
    public static List<Integer> isSelected = new ArrayList<Integer>();
    private int mColors[] = { R.drawable.progress_bg_item1, R.drawable.progress_bg_item2,R.drawable.progress_bg_item3,R.drawable.progress_bg_item4,R.drawable.progress_bg_item5};

    public VoteTopAdapter(Context mContext, ArrayList<String> mData,boolean isShowCheck){
        this.mContext = mContext;
        this.mData = mData;
        this.isShowCheck = isShowCheck;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.vote_item_top_layput,null);
            holder.mTitle = (TextView) view.findViewById(R.id.vote_item_title);
            holder.mCheck = (CheckBox) view.findViewById(R.id.vote_item_check);
            view.setTag(holder);

        }else{
            holder = (ViewHolder) view.getTag();
        }
        holder.mTitle.setText((char)(65 + i) + ": " + mData.get(i));
        if (!isShowCheck){
            holder.mCheck.setVisibility(View.GONE);
        }else{
            if (EventDetailContentActivity.index == i){
                holder.mCheck.setChecked(true);
            }else{
                holder.mCheck.setChecked(false);
            }
            if (isSelected.size() == 0){
                holder.mCheck.setChecked(false);
            }else{
                for (int j = 0; j < isSelected.size(); j++) {
                    if (i == isSelected.get(j)){
                        holder.mCheck.setChecked(true);
                        break;
                    }
                }
            }
//            holder.mCheck.setChecked(isSelected.get(i));
        }
        return view;
    }

    public void setShowCheck(boolean isShowCheck){
        this.isShowCheck = isShowCheck;
    }

    public class ViewHolder{
        TextView mTitle;
        public CheckBox mCheck;
    }

}
